﻿using System;
using System.Collections.Generic;

namespace KinectLibrary.DTWGestureRecognition
{
    public class GestureStream
    {
        private Queue<Frame> frames;
        private Frame lastFrame;
        private readonly int maxFrameCount;
        private long totalFrameCount;

        public GestureStream(int maxFrameCount)
        {
            lastFrame = null;
            this.maxFrameCount = maxFrameCount;
            frames = new Queue<Frame>(maxFrameCount + 1);
        }
        
        public void AddFrame(Frame frame)
        {
            lastFrame = frame;

            frames.Enqueue(frame);
            if (frames.Count > maxFrameCount)
                frames.Dequeue();

            totalFrameCount++;
        }

        /// <summary>
        /// Convert frames stored in the stream to a gesture object.
        /// </summary>
        /// <returns></returns>
        public Gesture ToGesture()
        {
            return new Gesture(frames); //<cambio>
        }

        public List<Frame> ToList()
        {
            return new List<Frame>(frames); //<cambio>
        }
        
        /// <summary>
        /// Remove all stored frames from the stream.
        /// </summary>
        public void Clear()
        {
            frames.Clear();
        }

        /// <summary>
        /// Returns true if the stream has its maximum number of frames;
        /// Otherwise false.
        /// </summary>
        public bool IsSaturated
        {
            get { return frames.Count == maxFrameCount; }
        }

        public int FrameCount
        {
            get { return frames.Count; }
        }

        public long AccumulatedFrameCount { get { return totalFrameCount; } }

        public int MaxFrames
        {
            set { frames = new Queue<Frame>(value);}
        }

        public Frame LastFrame
        {
            get { return lastFrame; }
        }
    }
}